function postAjaxProxy(url, data, successFunction) {
    return ajaxProxy(url, "POST", data, successFunction, function (data) {
        alert("接口调用错误");
    });
}

function getAjaxProxy(url, data, successFunction) {
    return ajaxProxy(url, "GET", data, successFunction, function (data) {
        alert("接口调用错误");
    });
}

function auth(data) {
    if (data.code == 1001) {
        var href = data.data;
        window.location.href = href;

    }
}

function ajaxProxy(url, method, data, successFunction, errorFunction) {
    $.ajax({
        contentType: "application/json; charset=utf-8",
        type: method,
        url: url,
        data: data,
        cache: false,
        async: false,
        dataType: "json",
        success: function (data) {
            if (data) {
                if (data.code == 0) {
                    successFunction(data);
                } else {
                    auth(data);
                }
            }
        },
        error: errorFunction
    });
}

function logout() {
    postAjaxProxy('/atomu/v1/venus/logout', '', function (data) {
        var href = data.data;
        window.location.href = href;
        //console.log('href='+href);
    });
}


function getUserInfo() {
    var loginInfo = null;
    postAjaxProxy('atomu/v1/venus/info', '', function (data) {
        loginInfo = data.data;
    });
    return loginInfo;
}

// var jsonReader config

var jsonReader = {
    root: "data",
    page: "currentPage",
    records: "totalCount",
    total: "extras.totalPage"
};

// common function

//查询商户信息
function getMerchantInfo() {
    var merchantSelectStr = "" + ":" + "请选择商户";
    getAjaxProxy("/atomu/v1/merchant/list",
        'orderStatus=1&_search=false&nd=1501836636152&rows=100&page=1&sidx=orderTime&sord=asc',
        function (data) {
            var merchantList = data.data;
            if (merchantList) {
                for (var i = 0; i < merchantList.length; i++) {
                    merchantSelectStr += ";" + merchantList[i].id + ":" + merchantList[i].merchantName;
                }
            }
        });
    return merchantSelectStr;
}

